package com.kool.leitu.aop;

import com.kool.leitu.annotation.KRequestAnnotation;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @description:
 * @author: tianhe
 * @create: 2018/10/30 23:46
 */
@Slf4j
@Component
@Aspect
public class AopTest {


    @Pointcut("execution(public * com.kool.leitu.controller.*.*(..)) || @annotation(com.kool.leitu.annotation.KRequestAnnotation)")
    public void request(){
    }


    @Around("request() && @annotation(kRequestId)")
    public Object arround(ProceedingJoinPoint joinPoint, KRequestAnnotation kRequestId) {
        try {
            log.info("请求["+kRequestId.value()+"]被代理");
            Object result = joinPoint.proceed();
            return result;
        } catch (Throwable e) {
            return null;
        }
    }
}
